package de.backtomedieval.scenarios;

import java.util.ArrayList;

import android.content.SharedPreferences;
import android.widget.EditText;
import android.widget.Spinner;


import de.backtomedieval.R;
import de.backtomedieval.game.Player;
import de.backtomedieval.main.Game;

public abstract class AbstractScenario {

	public long gametimeout = 0;

	public abstract String getName();
	public abstract String getDescription();
	public abstract boolean checkScenarioGameTimeout(long round);
	public abstract boolean checkWinConditions(Game game);
	public abstract int getID();
	public abstract void atGamestart();
	public abstract void onStartFight();
	
	private int state = -1;
	
	public AbstractScenario() {
		SharedPreferences settings = Game.getSharedPreferences(Game.PREFS_NAME, 0);

		int loadstate = settings.getInt("scenario"+getID()+"won", -1);
		this.state = loadstate;
	}
	
	
	
	public int getState() {
		return state;
	}
	public void setState(int state) {
		this.state = state;
	}
	public String getStateString() {
		String[] diff = Game.getStringArray(R.array.difficulty);
		if (state == -2) {
			return Game.getString(R.string.locked);
		} else if (state >= 0) {
			return Game.getString(R.string.completeat) +" " + diff[state];
		} else if (state == -1) {
			return Game.getString(R.string.notcomplete);
		} else {
			return "";
		}
	}
		
	public void winScenario() {
		if (Game.getDifficulty()>this.state) {
			// We need an Editor object to make preference changes.
			// All objects are from android.context.Context
			SharedPreferences settings = Game.getSharedPreferences(Game.PREFS_NAME, 0);
			SharedPreferences.Editor editor = settings.edit();
			editor.putInt("scenario"+getID()+"won", Game.getDifficulty());
			// Commit the edits!
			editor.commit();
		}
	}
	
	public static ArrayList<AbstractScenario> getScenarioList() {
		ArrayList<AbstractScenario> s = new ArrayList<AbstractScenario>();
		s.add(new DefendYourCityAgainst5Archers());
		s.add(new DefendYourCityAgainst10Longswordmen());
		s.add(new Defend_GreatSiege());
		s.add(new Defend_EvenGreaterSiege());
		s.add(new Defend_OnlyArcher());
		s.add(new Attack_Dragon());
		s.add(new Defend_Dragons());
		//s.add(new Fort_Sirena());
		//s.add(new BackToRoots());
		return s;
	}
	
	public boolean addStartFight() {
		return false;
	}
	
}
